'''
Created on 1 mar 2013

@author: Magnus
'''
from django.contrib.auth.models import BaseUserManager, UserManager

class MyUserManager(BaseUserManager):
    def create_user(self, username, email=None, password=None):

        if not email:
            raise ValueError('The given email must be set')
        email = UserManager.normalize_email(email)
        user = self.model(username=username, email=email) 
 
        user.set_password(password)
        user.save(using=self._db)
        return user
 
    def create_superuser(self, username, email, password):
        u = self.create_user(username, email, password)
        u.is_staff = True
        u.is_superuser = True
        u.save(using=self._db)
        return u
    
    